/******************************************************************************/
/*									GENERAL INFO			  				  */
/******************************************************************************/
/*

PROJECT 
	Paper: Using Communications Technology to Promote Democratic Participation: Experimental Evidence from South Africa
	Authors: A. Erlich, . Ferree, C. Gibson, D.F. Jung, J.D. Long, C. McIntosh

DO FILE

	This .do file produces the main paper and appendix results
	Inputs: PK_wide_clean_$date.dta
	Outputs: Tables 1-9 & A2, Figures 2 & 3

*/
/******************************************************************************/
/*									SETUP					  				  */
/******************************************************************************/

	clear all
	global date 211015
	set more off

	capture cd "~/Dropbox/RSA_RCT_SHARE/RSA_RCT_replication_files"
	
/* Merge and Clean data */ 
	
	*do "code/PK_data_1_merge_$date"
	*do "code/PK_data_2_clean_$date"
	
/* Install packages */
	
	*ssc install outreg2
	
	

	use "data/PK_wide_clean_$date", clear
	
	
gen social_media = (channel=="5. MXIT" | channel=="6. MOBI")
gen twitter = (channel=="7. Twitter" | channel=="8. Other")
label var ussd_treat_free "USSD Free Arm"
label var ussd_treat_lottery "USSD Lottery Arm"
label var social_media "Social Media user"
label var twitter "Twitter/Gtalk"

replace social_media = 0 if (ussd_treat_lottery==1 | ussd_treat_free==1)


gen eng_social_media = social_media
gen afr_social_media = (social_media==1 & lang=="af")
gen zulu_social_media = (social_media==1 & lang=="zu")	
label var eng_social_media "English Social Media"
label var afr_social_media "Afrikaans Social Media"
label var zulu_social_media "Zulu Social Media"
	
gen lan_choice_eng = (lang=="en") if lang!=""
gen lan_choice_af = (lang=="af") if lang!=""
gen lan_choice_zu = (lang=="zu") if lang!=""

gen new_group = "1. USSD Standard" if ussd_treat=="standard"
replace new_group = "2. USSD Free" if ussd_treat=="free"
replace new_group = "3. USSD Lottery" if ussd_treat=="lottery"
replace new_group = "4. USSD NonExp" if ussd_other==1
replace new_group = "5. English Social Media" if eng_social_media==1
replace new_group = "6. Zulu Social Media" if zulu_social_media==1
replace new_group = "7. Afrikaans Social Media" if afr_social_media==1
replace new_group = "8. Twitter" if twitter==1

gen phase4_ever = (end_or_vexp_ever==1 | gotv_respond==1)

label var ussd_other "USSD Non experimental"


gen new_new_group = new_group
replace new_new_group = "USSD_exp" if new_group=="1. USSD Standard"
replace new_new_group = "USSD_exp" if new_group=="2. USSD Free"
replace new_new_group = "USSD_exp" if new_group=="3. USSD Lottery"




gen monitorPush_other = ussd_other * monitorPush_treat
gen monitorPush_social = social_media * monitorPush_treat
gen monitorPush_zulu = zulu_social_media * monitorPush_treat
gen monitorPush_afr = afr_social_media * monitorPush_treat

gen high_engage = (engagement_yesvote==1)

gen Push_free_engage = monitorPush_free*high_engage
gen Push_lottery_engage = monitorPush_lottery*high_engage
gen Push_engage = monitorPush_treat*high_engage
gen free_engage = ussd_treat_free * high_engage
gen lottery_engage = ussd_treat_lottery * high_engage

gen social_engage = social_media * high_engage
gen monitorPush_social_engage = monitorPush_social * high_engage
gen ussd_engage = ussd_exp_SAMPLE * high_engage
gen monitorPush_ussd_engage = ussd_engage * monitorPush_treat

label var high_engage "Engaged"

label var monitorPush_free "Free*Incentive"
label var monitorPush_lottery "Lottery*Incentive"
label var monitorPush_social "SM*Incentive"
label var Push_free_engage "Free*Incentive*Engaged"
label var Push_lottery_engage "Lottery*Incentive*Engaged"
label var Push_engage "Incentive*Engaged"
label var free_engage "Free*Engaged"
label var lottery_engage "Lottery*Engaged"
label var social_engage "SM*Engaged"
label var monitorPush_social_engage "SM*Incentive*Engaged"

label var ussd_other "USSD Non-Experimental"


global demog_plus_dm "age_num_dm male_dm coloured_dm white_dm indian_or_asian_dm election2009_yes_dm"

label var age_num_dm "Age"
label var male_dm "Male"
label var coloured_dm "Coloured"
label var white_dm "White"
label var indian_or_asian_dm "Asian"
label var election2009_yes_dm "Voted 2009"


STOP
	







/******************************************************************************/
/*									ANALYSIS				  				  */
/******************************************************************************/

	
	
	
		
/*TABLE 1: Recruitment and Participation Numbers*/

/* Participation Waterfall */
preserve
collapse (sum) engagement_alt* monitorPush_SAMPLE phase3_volunteer_SAMPLE monitor_SAMPLE monitor_tally_ever phase4_ever, by(new_group)
list
restore
		
		


		
/*TABLE 2: Demographics of Participants, by Channel */

	preserve
	keep if registered==1
	collapse age_num male black_african coloured white indian_or_asian election2009_yes, by(new_group)
		
	
	
	

	

*TABLE 3:  Panel analysis of the push polling
*analyzing the push + thermometer questions as a long panel:
	eststo clear
preserve
keep lan_choice_af lan_choice_zu ussd_treat_free ussd_treat_lottery ussd_other eng_social_media afr_social_media zulu_social_media push_o_* push_ever anon_id stratum ussd_exp_SAMPLE demog_SAMPLE $demog_plus_dm
reshape long push_o_answered_ push_o_dow_ push_o_q_ , i(anon_id) j(order)
gen thermometer = (push_o_q_ == "thermometer")
gen monday = (push_o_dow_==1)
gen tuesday = (push_o_dow_==2)
gen wednesday = (push_o_dow_==3)
gen thursday = (push_o_dow_==4)
gen friday = (push_o_dow_==5)
gen saturday = (push_o_dow_==6)
gen doortodoor = (push_o_q_=="doortodoor")
gen intimidated = (push_o_q_=="intimidated")
gen foodmoney = (push_o_q_=="foodmoney")
gen rallies = (push_o_q_=="rallies")
gen violence = (push_o_q_=="violence")
gen protests = (push_o_q_=="protests")	
label var push_o_answered_ "Responded"
gen weekday = (push_o_dow>=1 & push_o_dow<=5)
gen order_2 = (order==2)
gen order_3 = (order==3)
gen order_4_5 = (order==4 | order==5)
label var order_2 "Second question"
label var order_3 "Third question"
label var order_4_5 "Fourth/Fifth question"
label var weekday "Weekday"
label var monday "Monday"
label var tuesday "Tuesday"
label var wednesday "Wednesday"
label var thursday "Thursday"
label var friday "Friday"
label var saturday "Saturday"
label var order "Order of question"
label var intimidated "Question is Intimidation"
label var rallies "Question is Rallies"
label var thermometer "Question is Poll"
label var violence "Question is Violence"
label var protests "Question is Protests"
label var doortodoor "Question is campaigning"
label var lan_choice_af "Afrikaans speaker"
label var lan_choice_zu "Zulu speaker"
regr push_o_answered_ ussd_treat_free ussd_treat_lottery  if ussd_exp_SAMPLE==1, cluster(anon_id)
		qui summ push_o_answered_ if stratum=="1. USSD_standard"
		estadd sca mdv = r(mean)
		est sto reg1
regr push_o_answered_ ussd_treat_free ussd_treat_lottery ussd_other eng_social_media afr_social_media zulu_social_media, cluster(anon_id)
		qui summ push_o_answered_ if stratum=="1. USSD_standard"
		estadd sca mdv = r(mean)
		est sto reg2
regr push_o_answered_ ussd_treat_free ussd_treat_lottery ussd_other eng_social_media afr_social_media zulu_social_media weekday order_2 order_3 order_4_5 thermometer   rallies violence doortodoor, cluster(anon_id)
		qui summ push_o_answered_ if stratum=="1. USSD_standard"
		estadd sca mdv = r(mean)
		est sto reg3
regr push_o_answered_ ussd_treat_free ussd_treat_lottery ussd_other eng_social_media afr_social_media zulu_social_media weekday order_2 order_3 order_4_5 thermometer   rallies violence doortodoor if demog_SAMPLE==1, cluster(anon_id)
		qui summ push_o_answered_ if stratum=="1. USSD_standard"
		estadd sca mdv = r(mean)
		est sto reg4
regr push_o_answered_ ussd_treat_free ussd_treat_lottery ussd_other eng_social_media afr_social_media zulu_social_media weekday order_2 order_3 order_4_5 thermometer   rallies violence doortodoor $demog_plus_dm if demog_SAMPLE==1, cluster(anon_id)
		qui summ push_o_answered_ if stratum=="1. USSD_standard"
		estadd sca mdv = r(mean)
		est sto reg5
esttab reg* using "output/push_longpanel.tex", keep(ussd_treat_free ussd_treat_lottery ussd_other eng_social_media afr_social_media zulu_social_media weekday order_2 order_3 order_4_5 thermometer   rallies violence doortodoor) ///
		replace b(%10.3f) se l sfmt(%10.3f) ///
		scalars("mdv Mean for USSD standard" "N Observations" "r2 R squared" ) ///
		star(* 0.10 ** 0.05 *** 0.01) compress nonotes width(\hsize) ///
		mtitles("\shortstack{USSD \\ Experimental}" "\shortstack{Whole \\ Sample}" "\shortstack{Question \\ timing}" "\shortstack{Sample \\ with demog}" "\shortstack{Controlling \\ for demog}") 		
	eststo clear
	est drop r*		

restore			
			
	
	
	
	
	

/*TABLE 4: Impact of Incentives on Volunteering to Monitor */

	
	/* impact of incentives on volunteering to monitor */
		regr phase3_volunteer_SAMPLE monitorPush_treat if registered_SAMPLE==1 & monitorPush_SAMPLE==1, robust
		qui summ phase3_volunteer_SAMPLE if stratum=="1. USSD_standard" & registered==1 & monitorPush_SAMPLE==1
		estadd sca mdv = r(mean)
		est sto reg1
	/* impact of incentives on volunteering to monitor */
		regr phase3_volunteer_SAMPLE monitorPush_treat ussd_treat_free ussd_treat_lottery ussd_other eng_social_media zulu_social_media afr_social_media twitter if registered_SAMPLE==1 & monitorPush_SAMPLE==1, robust
		qui summ phase3_volunteer_SAMPLE if stratum=="1. USSD_standard" & registered==1 & monitorPush_SAMPLE==1
		estadd sca mdv = r(mean)
		est sto reg2
	/* same but only in sample with demog */
		regr phase3_volunteer_SAMPLE monitorPush_treat ussd_treat_free ussd_treat_lottery ussd_other eng_social_media zulu_social_media afr_social_media twitter  if registered_SAMPLE==1 & monitorPush_SAMPLE==1 & demog_SAMPLE==1, robust
		qui summ phase3_volunteer_SAMPLE if stratum=="1. USSD_standard" & registered==1 & monitorPush_SAMPLE==1  & demog_SAMPLE==1
		estadd sca mdv = r(mean)
		est sto reg3
	/* now including demog as controls */
		regr phase3_volunteer_SAMPLE monitorPush_treat ussd_treat_free ussd_treat_lottery ussd_other eng_social_media zulu_social_media afr_social_media twitter  $demog_plus_dm if registered_SAMPLE==1 & monitorPush_SAMPLE==1, robust
		qui summ phase3_volunteer_SAMPLE if stratum=="1. USSD_standard" & registered==1 & monitorPush_SAMPLE==1  & demog_SAMPLE==1
		estadd sca mdv = r(mean)
		est sto reg4
		

esttab reg* using "output/incentives_volunteer.tex", keep(monitorPush_treat ussd_treat_free ussd_treat_lottery ussd_other eng_social_media zulu_social_media afr_social_media twitter) ///
		replace b(%10.3f) se l sfmt(%10.3f) ///
		scalars("mdv Mean for USSD standard" "N Observations" "r2 R squared" ) ///
		star(* 0.10 ** 0.05 *** 0.01) compress nonotes width(\hsize)  ///
	 mtitles("\shortstack{Monitor \\ Volunteered}" "\shortstack{Monitor \\ Volunteered}" "\shortstack{Sample \\ with demog}" "\shortstack{Controlling \\ for demog}") 		
	eststo clear
	est drop r*	



	
			
		

	
	
	
	

/*TABLE 5: Differential Impact of Subsequent Incentives on Participation */

	preserve
	label var monitorPush_free "Free x Incentivized"
	label var monitorPush_lottery "Lottery x Incentivized"
	label var monitorPush_treat "Incentivized"
	
	
	/*Phase 2 incentivized versus unincentivized survey questions:*/
		eststo clear
		regr particip_incentivized ussd_treat_free ussd_treat_lottery if registered_SAMPLE==1 & ussd_exp_SAMPLE==1 & isphonenumber==1, robust
			eststo 	reg1
			test (ussd_treat_free = ussd_treat_lottery)
			estadd scalar F1 = r(p):reg1
			qui summ particip_incentivized if stratum=="1. USSD_standard"
			estadd scalar ymean_control=r(mean):reg1
		regr particip_unincentivized ussd_treat_free ussd_treat_lottery if registered_SAMPLE==1 & ussd_exp_SAMPLE==1 & isphonenumber==1, robust
			eststo 	reg2
			test (ussd_treat_free = ussd_treat_lottery)
			estadd scalar F1 = r(p):reg2
			qui summ particip_unincentivized if stratum=="1. USSD_standard"
			estadd scalar ymean_control=r(mean):reg2
		regr prob_dif ussd_treat_free ussd_treat_lottery if registered_SAMPLE==1 & ussd_exp_SAMPLE==1 & isphonenumber==1, robust
			eststo 	reg3
			test (ussd_treat_free = ussd_treat_lottery)
			estadd scalar F1 = r(p):reg3
			qui summ prob_dif if stratum=="1. USSD_standard"
			estadd scalar ymean_control=r(mean):reg3
		regr prob_dif ussd_treat_free ussd_treat_lottery if registered_SAMPLE==1 & ussd_exp_SAMPLE==1 & isphonenumber==1  & demog_SAMPLE==1, robust
			eststo 	reg4
			test (ussd_treat_free = ussd_treat_lottery)
			estadd scalar F1 = r(p):reg4
			qui summ prob_dif if stratum=="1. USSD_standard"
			estadd scalar ymean_control=r(mean):reg4	
		regr prob_dif ussd_treat_free ussd_treat_lottery $demog_plus_dm if registered_SAMPLE==1 & ussd_exp_SAMPLE==1 & isphonenumber==1  & demog_SAMPLE==1, robust
			eststo 	reg5
			test (ussd_treat_free = ussd_treat_lottery)
			estadd scalar F1 = r(p):reg5
			qui summ prob_dif if stratum=="1. USSD_standard"
			estadd scalar ymean_control=r(mean):reg5	
					
	esttab reg1 reg2 reg3 reg4 reg5  using "output/table9_new.tex" ,starl(* 0.10 ** 0.05 *** 0.01) replace b(%10.3f) se l sfmt(%10.3f) ///
	  keep(ussd_treat_free ussd_treat_lottery  $demog_plus_dm) compress nonotes width(\hsize) ///
	  scalars("ymean_control Mean for USSD Standard"  "N Observations" "r2 R squared" "F1 Ftest Free vs Lottery") ///
	  		 mtitles("\shortstack{Answered \\ Incentivized}" "\shortstack{Answered \\ Unincentivized}" "\shortstack{Diff Prob \\ (Inc - Uninc)}" ///
			  "\shortstack{Sample \\ with demog}"  "\shortstack{Controlling \\ for demog}" )  
	restore
	
	
	
		
	
	
		
/*TABLE 6:  Dynamics of Extrinsic and Intrisic Motivation:*/

	eststo clear
regr phase3_volunteer_SAMPLE monitorPush_treat   ussd_treat_free ussd_treat_lottery  monitorPush_free monitorPush_lottery  if ussd_exp_SAMPLE==1 & registered_SAMPLE==1 & monitorPush_SAMPLE==1 , robust
		qui summ phase3_volunteer_SAMPLE if stratum=="1. USSD_standard" & registered==1 & monitorPush_SAMPLE==1 
		estadd sca mdv = r(mean)
		est sto reg1
regr phase3_volunteer_SAMPLE monitorPush_treat   ussd_treat_free ussd_treat_lottery  monitorPush_free monitorPush_lottery ///
		high_engage  Push_engage    ///
	if registered_SAMPLE==1 & monitorPush_SAMPLE==1 & ussd_exp_SAMPLE==1 , robust		
		qui summ phase3_volunteer_SAMPLE if stratum=="1. USSD_standard" & registered==1 & monitorPush_SAMPLE==1  
		estadd sca mdv = r(mean)
		est sto reg2		
regr phase3_volunteer_SAMPLE  Push_engage   monitorPush_treat  high_engage ///
	if registered_SAMPLE==1 & monitorPush_SAMPLE==1 & social_media==1 , robust				
		qui summ phase3_volunteer_SAMPLE if eng_social_media==1 & registered==1 & monitorPush_SAMPLE==1  
		estadd sca mdv = r(mean)
		est sto reg3
regr phase3_volunteer_SAMPLE  monitorPush_free monitorPush_lottery  monitorPush_social  monitorPush_treat ///
	ussd_treat_free ussd_treat_lottery  social_media high_engage Push_engage monitorPush_social_engage if (ussd_exp_SAMPLE==1 | social_media==1) & registered_SAMPLE==1 & monitorPush_SAMPLE==1 , robust
		qui summ phase3_volunteer_SAMPLE if stratum=="1. USSD_standard" & registered==1 & monitorPush_SAMPLE==1  
		estadd sca mdv = r(mean)
		est sto reg4
regr phase3_volunteer_SAMPLE  monitorPush_free monitorPush_lottery  monitorPush_social  monitorPush_treat ///
	ussd_treat_free ussd_treat_lottery  social_media high_engage Push_engage monitorPush_social_engage if (ussd_exp_SAMPLE==1 | social_media==1) & registered_SAMPLE==1 & monitorPush_SAMPLE==1 & demog_SAMPLE==1, robust
		qui summ phase3_volunteer_SAMPLE if stratum=="1. USSD_standard" & registered==1 & monitorPush_SAMPLE==1  & demog_SAMPLE==1
		estadd sca mdv = r(mean)
		est sto reg5	
regr phase3_volunteer_SAMPLE  monitorPush_free monitorPush_lottery  monitorPush_social  monitorPush_treat ///
	ussd_treat_free ussd_treat_lottery  social_media high_engage Push_engage monitorPush_social_engage $demog_plus_dm if (ussd_exp_SAMPLE==1 | social_media==1) & registered_SAMPLE==1 & monitorPush_SAMPLE==1 & demog_SAMPLE==1, robust
		qui summ phase3_volunteer_SAMPLE if stratum=="1. USSD_standard" & registered==1 & monitorPush_SAMPLE==1  & demog_SAMPLE==1
		estadd sca mdv = r(mean)
		est sto reg6
esttab reg* using "output/incentives_vol_diff.tex", keep(monitorPush_free monitorPush_lottery  monitorPush_social  monitorPush_treat ///
	ussd_treat_free ussd_treat_lottery  social_media  high_engage  Push_engage monitorPush_social_engage ) ///
		replace b(%10.3f) se l sfmt(%10.3f) ///
		scalars("mdv Mean for base group" "N Observations" "r2 R squared" ) ///
		star(* 0.10 ** 0.05 *** 0.01) compress nonotes width(\hsize)  ///
	 mtitles("\shortstack{USSD \\ Only}" "\shortstack{USSD \\ Only}" "\shortstack{SM \\ Only}"  "\shortstack{Pooled}"  ///
	 "\shortstack{Sample \\ with demog}" "\shortstack{Controlling \\ for demog}" ) 		
	eststo clear
	est drop r*			
	
	
	
/* TABLE 7: Impact of Incentives on Actual Citizen Observing*/

	
label var monitor_incentivized "High Incentives"
*new version of above:	
eststo clear
cap est drop reg*
	regr monitor_tally_ever monitor_incentivized if registered_SAMPLE==1 & monitor_SAMPLE==1 & ussd_SAMPLE==1, robust
		qui summ monitor_tally_ever if stratum=="1. USSD_standard" & registered==1 & monitor_SAMPLE==1 
		estadd sca mdv = r(mean)
		est sto reg1
	regr anc_usable monitor_incentivized  if registered_SAMPLE==1 & monitor_SAMPLE==1 & ussd_SAMPLE==1, robust
		qui summ anc_usable if stratum=="1. USSD_standard" & registered==1 & monitor_SAMPLE==1 
		estadd sca mdv = r(mean)
		est sto reg2
	regr anc_usable monitor_incentivized  if registered_SAMPLE==1 & monitor_tally_ever==1 & ussd_SAMPLE==1, robust
		qui summ anc_usable if stratum=="1. USSD_standard" & registered==1 & monitor_SAMPLE==1 & monitor_tally_ever==1
		estadd sca mdv = r(mean)
		est sto reg3
	
esttab reg* using "output/actual_monitor.tex", keep(monitor_incentivized ) ///
		replace b(%10.3f) se l sfmt(%10.3f) ///
		scalars("mdv Mean for Low Incentive" "N Observations" "r2 R squared" ) ///
		star(* 0.10 ** 0.05 *** 0.01) compress nonotes width(\hsize)  ///
	 mtitles("\shortstack{Monitoring \\ Performed}" "\shortstack{Entered Usable \\ Data, whole sample}" "\shortstack{Entered Usable \\ Data, among respondents}") 		
	eststo clear
	est drop r*		

	
*Table 8 is cost benefit analysis; not statistical analysis.	




			 
		
/******************************************************************************/
/*									FIGURES					  				  */
/******************************************************************************/





/* FIGURE 2: Daily Opinion Polling on Average ANC support per day per channel */


preserve
keep ussd_treat_free ussd_treat_lottery eng_social_media afr_social_media zulu_social_media poll_anc* anon_id stratum new_group
reshape long poll_anc poll_anc_date poll_anc_source, i(anon_id) j(order)
label var poll_anc "Supports ANC"
label var poll_anc_date "Date of Poll"
	*keep if willvote==1
	global outcome poll_anc
	global timevar poll_anc_date
	collapse  $outcome, by($timevar new_group)
	sort $timevar new_group
	lowess $outcome $timevar if new_group=="USSD Standard", nograph gen(USSD_s) bwidth(.5)
	lowess $outcome $timevar if new_group=="USSD Free", nograph gen(USSD_f) bwidth(.5)
	lowess $outcome $timevar if new_group=="USSD Lottery", nograph gen(USSD_l) bwidth(.5)
	lowess $outcome $timevar if new_group=="Afrikaans Social Media", nograph gen(SM_af) bwidth(.5)
	lowess $outcome $timevar if new_group=="English Social Media", nograph gen(SM_en) bwidth(.5)
	lowess $outcome $timevar if new_group=="Zulu Social Media", nograph gen(SM_zu) bwidth(.5)
	lowess $outcome $timevar if new_group=="Twitter", nograph gen(twit) bwidth(.5)
	keep if $timevar<19855
	drop if $timevar<19824
	set scheme plotplainblind
	twoway line USSD_s $timevar, lpattern(solid) lwidth(thick) || line USSD_f $timevar, lpattern(dash) lwidth(thick) ||   ///
		line USSD_l $timevar, lpattern(shortdash) lwidth(thick) || line SM_en $timevar, lpattern(solid) ||    ///
		line SM_zu $timevar, lpattern(dash) || line SM_af $timevar, lpattern(shortdash)  || line twit $timevar, lpattern(dot) ,   ///
		legend(label(1 "USSD Standard") label(2 "USSD Free") label(3 "USSD Lottery") label(4 "English Social Media") label(5 "Zulu Social Media")  ///
		label(6 "Afrikaans Social Media") label(7 "Twitter")) title("Polling Outcomes relative to Actual Vote") ///
		ytitle("ANC Support from Polling Data") xtitle("Date") text(.2 19845.4 "Election Day", place(e)) xline(19850)   ///
		text(.621 19835.52 "Actual Election Outcome  X", place(e))   xline(19850) note("X indicates actual ANC vote share in National Assembly election") ///
		xlabel(minmax)  xlabel(19826 19833 19840 19847 19855, format(%tdDD-Mon))
	graph export "output/figure2_alt.png", replace
	restore	
	

/* FIGURE 3: Participation Rates by Activity and Channel */

preserve
	collapse (sum) engagement_answered2 registered phase_2_ever demog_ever phase3_volunteer_SAMPLE phase_4_ever gotv_respond monitorPush_SAMPLE, by(new_group)
	foreach x in engagement_answered2 registered phase_2_ever demog_ever  {
		gen f_`x' = `x'/engagement_answered2
		}
	foreach x in  phase3_volunteer_SAMPLE phase_4_ever gotv_respond {
		gen f_`x' = `x'/monitorPush_SAMPLE
		}
		gen ph_num = 1 if engagement_answered2
	gen rnd1 = f_engagement_answered2
	gen rnd2 = f_registered
	gen rnd3 = f_phase_2_ever
	gen rnd4 = f_demog_ever
	gen rnd5 = f_phase3_volunteer_SAMPLE
	gen rnd6 = f_phase_4_ever
	gen rnd7 = f_gotv_respond
	reshape long rnd, i(new_group) j(round)

	keep if round<=5
	gen USSD = rnd if new_group=="1. USSD Standard"
	gen Eng_Social_Media = rnd if new_group=="5. English Social Media"
	gen Afr_Social_Media = rnd if new_group=="6. Zulu Social Media"
	gen Zulu_Social_Media = rnd if new_group=="7. Afrikaans Social Media"
		set scheme plotplainblind
	tw line USSD round, lwidth(thick) lpattern(solid) ||  line Eng_Social_Media round, lpattern(longdash_dot) || line Afr_Social_Media  round, lpattern(shortdash) ||   ///
			line Zulu_Social_Media round, lpattern(dot) yscale(log)   ///
		xlabel(1 "Engagement" 2 "Register" 3 "Any Phase 2" 4 "Demographics" 5 "Volunteer" , angle(45)) xline(4.5)     ///
		text(.15 2 "Digital Participation", place(e)) text(.15 4.48 "Real-World", place(e))  ///
		ylabel(.05 .1 .2 .4 .6 .8 1) ytitle("Fraction Continuing, log scale") xtitle("Activity") 
	graph export "output/figure3.png", replace
restore




	
	
/***************************************************************************************************************************/
/***************************************************************************************************************************/
/***************************************************************************************************************************/
/***************************************************************************************************************************/
/***************************************************************************************************************************/
/***************************************************************************************************************************/
/***************************************************************************************************************************/
/*									APPENDIX TABLES																			*/
/***************************************************************************************************************************/
/***************************************************************************************************************************/
/***************************************************************************************************************************/
	

	
		
	
*Table A-2 responses to the What's Up questions:	
/*All whatsup questions:		
whatsup_ever whatsup_food_to_eat whatsup_frequency_campa whatsup_frequency_intim whatsup_frequency_party whatsup_not_voting ///
	whatsup_satisfied_democ whatsup_trust_anc whatsup_trust_da whatsup_trust_eff whatsup_violence_for_ju			{		
*/	
preserve
foreach x in ever  frequency_campa frequency_intim  violence_for_ju ///
	satisfied_democ trust_anc trust_da  			{
	rename whatsup_`x' `x'
		regr `x' ussd_other eng_social_media afr_social_media zulu_social_media twitter if  registered==1, robust
		qui summ `x' if stratum=="1. USSD_standard"
		estadd sca mdv = r(mean)
		est sto reg`x'_a
		}		

esttab reg* using "output/whats_up.tex", keep(ussd_other eng_social_media afr_social_media zulu_social_media twitter) ///
		replace b(%10.3f) se l sfmt(%10.3f) ///
		scalars("mdv Mean for USSD standard" "N Observations" "r2 R squared" ) ///
		star(* 0.10 ** 0.05 *** 0.01) compress nonotes width(\hsize)  ///
		 mtitles("\shortstack{WhatsUp \\ Ever \\ (binary)}" "\shortstack{Campaign \\ Rallies \\ (0-3)}" "\shortstack{Voter \\ Intimidation \\ (0-3)}"  "\shortstack{Violence \\ is justified \\ (0-3)}" ///
					"\shortstack{Satisfied \\ Democracy \\ (0-3)}" "\shortstack{Trust \\ ANC \\ (0-4)}" "\shortstack{Trust \\ DA \\ (0-4)}") 
	eststo clear
	est drop r*			
restore			
		
		
		
*Table A-3 responses to the VIP questions:
/*All VIP questions:
vip_attend_protest vip_registered vip_likelyvote vip_likeanc vip_likeda vip_protests vip_violence vip_neighbors vip_neigh_judge 
	vip_zuma_perf vip_local_perf vip_partycontact vip_attendrally vip_ever */
	eststo clear
	preserve
foreach x in ever registered likelyvote zuma_perf local_perf  attendrally	attend_protest		{
		regr vip_`x' ussd_other eng_social_media afr_social_media zulu_social_media twitter if  registered==1, robust
		qui summ vip_`x' if stratum=="1. USSD_standard"
		estadd sca mdv = r(mean)
		est sto reg`x'_a
		}		

esttab reg* using "output/vip.tex", keep(ussd_other eng_social_media afr_social_media zulu_social_media twitter) ///
		replace b(%10.3f) se l sfmt(%10.3f) ///
		scalars("mdv Mean for USSD standard" "N Observations" "r2 R squared" ) ///
		star(* 0.10 ** 0.05 *** 0.01) compress nonotes width(\hsize)  ///
		 mtitles("\shortstack{VIP \\ Ever \\ (binary)}" "\shortstack{Registered \\ to vote \\ (binary)}" "\shortstack{Likely \\ to vote \\ (0-3)}" ///
				"\shortstack{Zuma \\ Performance \\ (0-3)}"  "\shortstack{Local Govt \\ Performance \\ (0-3)}"  ///
					"\shortstack{Attend \\ Rally \\ (binary)}" "\shortstack{Attended \\ Protests \\ (0-2)}") 
	eststo clear
	est drop r*			
restore	
	

	

*Table A-4 responses to the Thermometer questions:		
preserve
gen answered_therm1 = (therm_anc1!=. |  therm_da1!=.)
gen answered_therm2 = (therm_anc2!=. |  therm_da2!=.)
foreach x in answered_therm1  therm_anc1 therm_da1 answered_therm2 therm_anc2 therm_da2		{
		regr `x' ussd_other eng_social_media afr_social_media zulu_social_media  if  registered==1 & therm_asked==1, robust
		qui summ `x' if stratum=="1. USSD_standard"
		estadd sca mdv = r(mean)
		est sto reg`x'_a
		}		

esttab reg* using "output/thermometer.tex", keep(ussd_other eng_social_media afr_social_media zulu_social_media) ///
		replace b(%10.3f) se l sfmt(%10.3f) ///
		scalars("mdv Mean for USSD standard" "N Observations" "r2 R squared" ) ///
		star(* 0.10 ** 0.05 *** 0.01) compress nonotes width(\hsize)  ///
		 mtitles("\shortstack{Answered \\ first push \\ (binary)}" "\shortstack{Support  \\ ANC \\ (binary)}" "\shortstack{Support \\ DA \\ (binary)}"  ///
			"\shortstack{Answered  \\ second push \\ (binary)}" "\shortstack{Support \\ ANC \\ (binary)}" "\shortstack{Support \\ DA \\ (binary)}") 
	eststo clear
	est drop r*			
restore	
		

		

		
		
		
*Table A-5 responses to the Push questions:	
preserve
foreach x in ever doortodoor intimidated foodmoney rallies violence protests  			{
	rename push_`x' `x'
		regr `x' ussd_other eng_social_media afr_social_media zulu_social_media   if  registered==1 & push_asked==1, robust
		qui summ `x' if stratum=="1. USSD_standard"
		estadd sca mdv = r(mean)
		est sto reg`x'_a
		}		

esttab reg* using "output/push.tex", keep(ussd_other eng_social_media afr_social_media zulu_social_media) ///
		replace b(%10.3f) se l sfmt(%10.3f) ///
		scalars("mdv Mean for USSD standard" "N Observations" "r2 R squared" ) ///
		star(* 0.10 ** 0.05 *** 0.01) compress nonotes width(\hsize)  ///
		 mtitles("\shortstack{Ever answer \\ push \\ (binary)}" "\shortstack{Campaigning \\ door-to-door \\ (binary)}" "\shortstack{Voter \\ indimidatation \\ (binary)}" "\shortstack{Vote buying \\ with food \\ (binary)}"  "\shortstack{Political \\ rallies \\ (binary)}" ///
					"\shortstack{Political \\ violence \\ (binary)}" "\shortstack{Political \\ protests \\ (binary)}") 
	eststo clear
	est drop r*			
restore			
		

		
*Table A-6 responses to the Voter Experience questions:	
preserve
gen vexperience_ever = 0 if registered==1
foreach x in vexperience_privacyadequate vexperience_didyouvote vexperience_tension vexperience_intimidation vexperience_campaigning vexperience_iec vexperience_queue vexperience_materials vexperience_violence {
	replace vexperience_ever = 1 if `x'!=.
	}
foreach x in ever  queue  materials iec   intimidation tension violence  			{
	rename vexperience_`x' `x'
		regr `x' ussd_other eng_social_media afr_social_media zulu_social_media   if registered==1 , robust
		qui summ `x' if stratum=="1. USSD_standard"
		estadd sca mdv = r(mean)
		est sto reg`x'_a
		}		

esttab reg* using "output/vexperience.tex", keep(ussd_other eng_social_media afr_social_media zulu_social_media) ///
		replace b(%10.3f) se l sfmt(%10.3f) ///
		scalars("mdv Mean for USSD standard" "N Observations" "r2 R squared" ) ///
		star(* 0.10 ** 0.05 *** 0.01) compress nonotes width(\hsize)  ///
	 mtitles("\shortstack{Ever  \\ answer \\ (binary)}" "\shortstack{Length of  \\ Queue \\ (minutes)}" "\shortstack{Materials \\ Correct \\ (binary)}" ///
		"\shortstack{Confidence  \\ in IEC \\ (0-3)}"  "\shortstack{Voter \\ intimidation \\ (binary)}" ///
					"\shortstack{Electoral \\ tension \\ (0-2)}" "\shortstack{Electoral \\ violence \\ (binary)}") 		
	eststo clear
	est drop r*		
restore			




		
		
	
/*TABLE A-7: Engagement by Channel */

	preserve
	keep if registered==1
	drop if engagement_tooyoung==1
	tabstat engagement_yesvote engagement_novoteanyway engagement_refuse engagement_unregistered, missing by(new_new_group) stat(mean )
	restore
	
	

	
/* TABLE A-8: PCM Recruitment Experiment*/


	preserve
	collapse (sum) registered, by(stratum)
	list
	restore


*getting treatment effects and confidence intervals on the treatment effects for the PCM experiment
preserve
use "data/PCM_dummy_dataset", clear
expand = number
bysort treat:  sum(took) 
regr took free lottery, robust
	
		
	
	
	
	
/* TABLE A-9:  Balance of the original (randomized) monitoring invitations */
eststo clear
preserve
	foreach x in ussd_treat_free ussd_treat_lottery social_media  phase_2_ever  demog_ever  engagement_yesvote age_num male election2009_yes  {
		regr `x' monitorPush_treat if registered_SAMPLE==1 & monitorPush_SAMPLE==1, robust
			qui summ `x' if monitorPush_treat==0 & registered_SAMPLE==1 & monitorPush_SAMPLE==1 
			estadd sca mdv = r(mean)
			est sto reg`x'
		}
		
	esttab   regussd_treat_free regussd_treat_lottery regsocial_media regphase_2_ever  regdemog_ever  regengagement_yesvote regage_num regmale regelection2009_yes  ///
		using "output/balance_monitor_invitation.tex" ,starl(* 0.10 ** 0.05 *** 0.01) replace b(%10.3f) se l sfmt(%10.3f) ///
	  keep(monitorPush_treat) compress nonotes width(\hsize) ///
	  scalars("mdv Mean for unincentived"  "N Observations" "r2 R squared") ///
	  		 mtitles("\shortstack{USSD \\ Free}" "\shortstack{USSD \\ Lottery}" "\shortstack{Social \\ Media}""\shortstack{Any \\ Phase 2}" "\shortstack{Any \\ Demog}"  "\shortstack{High \\ Engagement}"  ///
			 "\shortstack{Age \\ }" "\shortstack{Male \\ }" "\shortstack{Voted \\ 2009}" )  
eststo clear
restore			




/* TABLE A-10: Balance of the Monitoring Incentive Invitations (non-randomized) as Actually Performed */

eststo clear
preserve
label var monitor_incentivized "High Monitoring Incentive"
	foreach x in   phase_2_ever vip_ever demog_ever  phase3_volunteer_SAMPLE engagement_yesvote age_num male election2009_yes  {
		regr `x' monitor_incentivized if registered_SAMPLE==1 & monitor_SAMPLE==1, robust
			qui summ `x' if monitor_incentivized==0 & registered_SAMPLE==1 & monitor_SAMPLE==1 
			estadd sca mdv = r(mean)
			est sto reg`x'
		}
		
	esttab   regphase_2_ever regdemog_ever regphase3_volunteer_SAMPLE regengagement_yesvote regage_num regmale regelection2009_yes  ///
		using "output/balance_new.tex" ,starl(* 0.10 ** 0.05 *** 0.01) replace b(%10.3f) se l sfmt(%10.3f) ///
	  keep(monitor_incentivized) compress nonotes width(\hsize) ///
	  scalars("mdv Mean for unincentived"  "N Observations" "r2 R squared") ///
	  		 mtitles("\shortstack{Any \\ Phase 2}" "\shortstack{Any \\ Demog}" "\shortstack{Volunteer  \\ Sample}" "\shortstack{High \\ Engagement}"  ///
			 "\shortstack{Age \\ }" "\shortstack{Male \\ }" "\shortstack{Voted \\ 2009}" )  

			 
			 	
	
	

		 


